//
//  OrderDishesCell.m
//  OrderSeat
//
//  Created by 王威 on 14-1-31.
//  Copyright (c) 2014年 wangwei. All rights reserved.
//

#import "OrderDishesCell.h"

@implementation OrderDishesCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setContent:(NSDictionary *)dic
{
    self.dictionary = dic;
        
    if (![dic objectForKey:@"cpname"]) {
        [self setTotalContent:dic];
        [self reLayoutTotalSubviews];
        return;
    }
    
    NSString *name = [dic objectForKey:@"cpname"];
    NSString *price = [NSString stringWithFormat:@"￥%@",[dic objectForKey:@"price"]];
    NSString *unit = [NSString stringWithFormat:@"/%@",[dic objectForKey:@"danwei"]];
    NSString *count = [[dic objectForKey:@"fenshu"] stringValue];
    
    self.unitLabel.text = unit;
    self.nameLabel.text = name;
    self.priceLabel.text = price;
    self.countLabel.text = count;
    
    [self reLayoutSubviews];
}

- (void)reLayoutSubviews
{
    self.nameLabel.left = 20;
    [self.nameLabel autoWidthForSingleLine];
    
    self.priceLabel.left = 150;
    [self.priceLabel autoWidthForSingleLine];
    
    self.unitLabel.left = self.priceLabel.right;
    [self.unitLabel autoWidthForSingleLine];
}

- (void)setTotalContent:(NSDictionary *)dic
{
    NSString *zongjia = [dic objectForKey:@"zongjia"];
    NSString *zongfenshu = [dic objectForKey:@"zongfenshu"];
    
    UILabel *totalMoneyLabel = (UILabel *)[self.contentView viewWithTag:1001];
    UILabel *totalCountLabel = (UILabel *)[self.contentView viewWithTag:1002];
    
    totalMoneyLabel.text = [NSString stringWithFormat:@"￥%@",zongjia];;
    totalCountLabel.text = [NSString stringWithFormat:@"/%@道",zongfenshu];
    
    [totalMoneyLabel autoWidthForSingleLine];
    [totalCountLabel autoWidthForSingleLine];
    totalCountLabel.left = totalMoneyLabel.right;
}

- (void)reLayoutTotalSubviews
{
    [_totalCountLabel autoWidthForSingleLine];
    [_totalMoneyLabel autoWidthForSingleLine];
    
    _totalCountLabel.left = _totalMoneyLabel.right;
}

@end
